package cn.com.pureAppApi.swagger;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * * QQ讨论群:76989293
 * @email 2696701142@qq.com
 * @date 2018-06-12 16:51:48
 */
@Configuration
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
@EnableSwagger2
@ConditionalOnClass(Docket.class)
public class Swagger2Configuration {
	
	@Autowired(required=false) private List<Parameter> parameterList;
    @Bean
    @ConditionalOnMissingBean(Docket.class)   
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.globalOperationParameters(parameterList)
				.select()
				.apis(RequestHandlerSelectors.basePackage("cn.com.pureAppApi.controller"))
				.paths(PathSelectors.any())
				.build();
	}

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("拿来即用 Spring Boot中使用Swagger2 UI构建API文档 QQ讨论群:76989293")
                .contact("纯粹AppAPI:Code-pureAPI 技术交流QQ:2696701142")
                .version("1.0")
                .build();
    }
}

